#include <stdio.h>
#include <cuda_runtime.h>

using namespace std;

// 方式2，__device__定义
__device__ float globalArray[100];

static __global__ void testKernel(float* devicePtr) {
    printf("devicePtr is global = %s\n", __isGlobal(devicePtr) ? "true" : "false");  // true
    printf("globalMemory is global = %s\n", __isGlobal(&globalArray) ? "true" : "false");  // true
}

int main() {
    // 方式1，主机分配
    float* deviceptr = nullptr;
    cudaMalloc(&deviceptr, sizeof(float) * 100);

    testKernel<<<1, 1>>>(deviceptr);
    cudaDeviceSynchronize();

    return 0;
}

// devicePtr is global = true
// globalMemory is global = true